/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

#include "Types.h"

#include "common/Empty.h"
#include "common/BigEndianUnsignedByte.h"
#include "common/BigEndianUnsignedShort.h"
#include "common/U16ArrayByte.h"
#include "common/U8Ascii.h"

#include "meta/MetaExpression.h"
#include "meta/MetaAbstract.h"
#include "meta/MetaArray.h"
#include "meta/MetaBasic.h"
#include "meta/MetaDefinition.h"
#include "meta/MetaEncoding.h"
#include "meta/MetaMap.h"
#include "meta/MetaName.h"
#include "meta/MetaReference.h"
#include "meta/MetaSequence.h"

#include "TypeMapCore.h"

int type_map_core_ids[] = { EMPTY_ID, UINT8_ID, UINT16_ID, BASIC_ID, ABSTRACT_ID,
	MAP_ID, EXPRESSION_ID, SEQUENCE_ID, REFERENCE_ID, NAME_ID, ENCODED_ID, ARRAY_ID,
	EXPRESSION_REFERENCE_ID, EXPRESSION_SEQUENCE_ID, EXPRESSION_ARRAY_ID,
	EXPRESSION_ENCODING_ID, DEFINITION_ID, DEFINITION_BASIC_ID, DEFINITION_MAP_ID,
	DEFINITION_SEQUENCE_ID, DEFINITION_ABSTRACT_ID };

static int make_map( reference_type_map * map, int id, type_name * name )
{
	type_library * library = type_map_get_library( &map->map );
	int rc = type_library_get_id( library, name );
	if ( rc <= NOTYPE )
		return rc;
	
	rc = type_map_map( &map->map, id, rc );
	if ( rc < TYPE_OK )
		return rc;
	
	return TYPE_OK;
}

int type_map_core_init( reference_type_map * map )
{
	int rc;
	
	if ( (rc = make_map( map, EMPTY_ID, &empty_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, UINT8_ID, &uint8_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, UINT16_ID, &uint16_name )) != TYPE_OK ) return rc;	
	if ( (rc = make_map( map, BASIC_ID, &meta_basic_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, ABSTRACT_ID, &meta_abstract_name )) != TYPE_OK ) return rc;	
	if ( (rc = make_map( map, MAP_ID, &meta_map_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, EXPRESSION_ID, &meta_expression_name )) != TYPE_OK ) return rc;		
	if ( (rc = make_map( map, SEQUENCE_ID, &meta_sequence_name )) != TYPE_OK ) return rc;	
	if ( (rc = make_map( map, REFERENCE_ID, &meta_reference_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, NAME_ID, &meta_name_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, ENCODED_ID, &meta_encoding_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, ARRAY_ID, &meta_array_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, EXPRESSION_REFERENCE_ID, &meta_expression_reference_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, EXPRESSION_SEQUENCE_ID, &meta_expression_sequence_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, EXPRESSION_ARRAY_ID, &meta_expression_array_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, EXPRESSION_ENCODING_ID, &meta_expression_encoding_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, DEFINITION_ID, &meta_definition_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, DEFINITION_BASIC_ID, &meta_definition_basic_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, DEFINITION_MAP_ID, &meta_definition_map_name )) != TYPE_OK ) return rc;	
	if ( (rc = make_map( map, DEFINITION_SEQUENCE_ID, &meta_definition_sequence_name )) != TYPE_OK ) return rc;
	if ( (rc = make_map( map, DEFINITION_ABSTRACT_ID, &meta_definition_abstract_name )) != TYPE_OK ) return rc;
	
	return TYPE_OK;	
}	
